﻿using Newtonsoft.Json;
using PSDLib.Protocols;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace PSDClientListener
{
    class Program
    {
        static void Main(string[] args)
        {
            //System.IO.FileStream fs = new System.IO.FileStream(@"d:\wsdl.exe", System.IO.FileMode.Open, System.IO.FileAccess.Read);

            //VersionFileMessage msg = new VersionFileMessage();
            //msg.File = new byte[Convert.ToInt32(fs.Length)];

            //fs.Read(msg.File, 0, msg.File.Length);

            //fs.Close();
            //fs.Dispose();

            //string json = JsonConvert.SerializeObject(msg);

            //var outputBuffer = Encoding.UTF8.GetBytes(json);

            //string recvStr = Encoding.UTF8.GetString(outputBuffer);

            //VersionFileMessage msg2 = JsonConvert.DeserializeObject<VersionFileMessage>(recvStr);


            //System.IO.FileStream fs1 = new System.IO.FileStream(@"d:\wsdl_1.exe", System.IO.FileMode.Create, System.IO.FileAccess.Write);

            //fs1.Write(msg2.File, 0, msg2.File.Length);

            //fs1.Close();
            //fs1.Dispose();



            if (args.Length > 0)
            {
                var listener = new PSDClientListener.ClientListener();

                listener.Init("c", false);
                listener.Start();

                while (Console.ReadLine() != "exit")
                { }

                listener.Stop();
                listener.Dispose();
            }
            else
            {
                ServiceBase[] ServiceToRun = new ServiceBase[] { new PSDClientListenerService() };

                ServiceBase.Run(ServiceToRun);
            }
        }
    }
}
